/*
 * Copyright 2017 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kie.workbench.common.stunner.bpmn.definition.property.event.message;

import java.util.Objects;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
import org.kie.workbench.common.forms.adf.definitions.annotations.metaModel.FieldDefinition;
import org.kie.workbench.common.forms.adf.definitions.annotations.metaModel.FieldValue;
import org.kie.workbench.common.forms.adf.definitions.annotations.metaModel.I18nMode;
import org.kie.workbench.common.stunner.bpmn.definition.BPMNProperty;
import org.kie.workbench.common.stunner.core.definition.annotation.Property;
import org.kie.workbench.common.stunner.core.definition.annotation.property.Value;

@Portable
@Bindable
@Property
@FieldDefinition(i18nMode = I18nMode.OVERRIDE_I18N_KEY)
public class MessageRef implements BPMNProperty {

    @Value
    @FieldValue
    private String value;

    private String structure;

    public MessageRef() {
        this("", "");
    }

    public MessageRef(@MapsTo("value") final String value, @MapsTo("structure") final String structure) {
        this.value = value;
        this.structure = structure;
    }

    public String getValue() {
        return value;
    }

    public void setValue(final String value) {
        this.value = value;
    }

    public String getStructure() {
        return structure;
    }

    public void setStructure(String structure) {
        this.structure = structure;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof MessageRef)) {
            return false;
        }
        MessageRef that = (MessageRef) o;
        return Objects.equals(getValue(), that.getValue()) &&
                Objects.equals(getStructure(), that.getStructure());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getValue(), getStructure());
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("MessageRef{");
        sb.append("value='").append(value).append('\'');
        sb.append(", structure='").append(structure).append('\'');
        sb.append('}');
        return sb.toString();
    }
}